//
//  BQMineTableViewController.m
//  BeeQuick
//
//  Created by Asun on 2017/7/9.
//  Copyright © 2017年 BecomeRich. All rights reserved.
//

#import "BQMineTableViewController.h"
#import "BQMineTopView.h"
#import "BQMineCellModel.h"
#import "BQMineSetController.h"
//v2_my_avatar
//v2_my_avatar-1
//v2_my_settings_icon
#import "BQMineHeaderView.h"
@interface BQMineTableViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,weak)BQMineTopView * topView;

@property(nonatomic,weak)UIView          *headerView;

@property(nonatomic,strong)NSArray *cellDataArray;
@end

@implementation BQMineTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self cellOfData];
    [self addTopView];
    [self addTableView];

}

- (void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBar.hidden = YES;
}

#pragma __UITableViewDelegate__
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
}

#pragma 获取cell显示内容的数据

- (void)cellOfData{
    NSString *flieName = [[NSBundle mainBundle]pathForResource:@"MineCell.plist" ofType:nil];
    NSArray *outArray = [NSArray arrayWithContentsOfFile:flieName];
    NSMutableArray *outMutableArray = [NSMutableArray array];
    for (int i = 0; i< outArray.count; i++) {
        NSArray *inArray = outArray[i];
        NSMutableArray *inMutableArray  = [NSMutableArray array];
        for (NSDictionary *dict in  inArray) {
            BQMineCellModel *model = [BQMineCellModel new];
            [model setValuesForKeysWithDictionary:dict];
            [inMutableArray addObject:model];
        }
        [outMutableArray addObject:inMutableArray.copy];
    }
    self.cellDataArray = outMutableArray.copy;
}

#pragma __addTableView__

- (void)addTableView{

    UITableView *tableView = [[UITableView alloc]init];
    tableView.dataSource = self;
    tableView.delegate = self;
    BQMineHeaderView *headerView = [[BQMineHeaderView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 80)];
    headerView.HeaderOfBlock = ^(NSInteger tag){
        switch (tag) {
            case 0:
                NSLog(@"你点击了我的订单");
                break;
            case 1:
                NSLog(@"你点击了我的优惠券");
                break;
            case 2:
                NSLog(@"你点击了我的消息");
            default:
                break;
        }
        
    };
    tableView.tableHeaderView = headerView;
    tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"BQMineTableViewControllerCell"];
    [self.view addSubview:tableView];
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView.mas_bottom);
        make.leading.trailing.bottom.equalTo(self.view);
    }];
    tableView.tableFooterView = [UIView new];
}


#pragma __topView__
- (void)addTopView{
    BQMineTopView *topView = [[BQMineTopView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)];
    self.topView = topView;
    topView.topViewBlock = ^{
        BQMineSetController *setVC = [[BQMineSetController alloc]init];
        [self.navigationController pushViewController:setVC animated:NO];
    };
    [self.view addSubview:topView];
}

#pragma __UITableViewDataSource__

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.cellDataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *tempArray = self.cellDataArray[section];
    return tempArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BQMineTableViewControllerCell" forIndexPath:indexPath];
    NSArray *modelArray = self.cellDataArray[indexPath.section];
    BQMineCellModel *model = modelArray[indexPath.row];
    cell.imageView.image = [UIImage imageNamed:model.icon];
    cell.imageView.transform = CGAffineTransformScale(cell.imageView.transform, 1.5, 1.5);
    cell.textLabel.text = model.title;
    cell.textLabel.textColor = [UIColor grayColor];
    if (indexPath.section == 0 && indexPath.row == 0) {
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 1)];
        lineView.backgroundColor = [UIColor lightGrayColor];
        [cell.contentView addSubview:lineView];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 0;
    }
    return 20;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}

@end
